#include "S3C6410CameraSourceFilter.h"

using namespace Poco;

namespace cm_media
{
    S3C6410CameraSourceFilter::S3C6410CameraSourceFilter()
                                :m_stopFlag(false),
                                m_pool(NULL),
                                m_outputPin(NULL),
                                m_captureTimerInitd(false)

    {
        
    }

    S3C6410CameraSourceFilter::~S3C6410CameraSourceFilter()
    {

    }

    int S3C6410CameraSourceFiltersetup()
    {
        return CmMediaFail;
    }

    int S3C6410CameraSourceFilterteardown()
    {
        return CmMediaFail;
    }

    int S3C6410CameraSourceFilter::enqueueBuffer( ByteBuffer*p_buffer )
    {
        return CmMediaFail;
    }

    void S3C6410CameraSourceFilter::startCaptureTimer(long milliseconds)
    {
        if( m_captureTimerInitd ){
            m_timer.restart( milliseconds );
        }else{
            m_timer.setPeriodicInterval(milliseconds);
            m_timer.start( TimerCallback<S3C6410CameraSourceFilter>( (*this), &S3C6410CameraSourceFilter::cbCaptureTimer));
        }
    }

    void S3C6410CameraSourceFilter::stopCaptureTimer()
    {
        m_timer.stop();
    }

    void S3C6410CameraSourceFilter::cbCaptureTimer(Timer& timer)
    {
        enqueueNotification( new CaptureTimerNotification, 0);
    }


    void S3C6410CameraSourceFilter::run()
    {
        BaseNotification* p_bn = NULL;

        while(!m_stopFlag){
            
            p_bn = (BaseNotification*)waitDequeueNotification(10000);
            if( p_bn )
            {
                switch( p_bn->getType() )
                {
                case  NotificationTypeOnCaptureTimer:
                    {
                        std::cout<< "\nNOTIFICATION_TYPE_CAPTURE_TIMER";
                        p_bn->release();
                    }
                    break;
                default:
                    {
                        p_bn->release();
                    }
                }
                
            }
            
            p_bn = NULL;
        }

    }


}
